package bitWork;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: tao
 * Date: 2023-12-02
 * Time: 13:30
 */
public class Work2 {
    public static int AA = 0;
    public static void main(String[] args) {
        Object locker = new Object();
        Thread C = new Thread(() -> {
            for(int i = 0; i < 10; i++) {
                synchronized (locker) {
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println("C");
                    locker.notifyAll();
                }
            }
        });
        Thread B = new Thread(() -> {
            for(int i = 0; i < 10; i++) {
                synchronized (locker) {
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.print("B");
                    locker.notifyAll();
                }
            }
        });
        Thread A = new Thread(() -> {
            for(int i = 0; i < 10; i++) {
                synchronized (locker) {
                    System.out.print("A");
                    locker.notifyAll();
                    try {
                        locker.wait();
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }

                }
            }
        });
        A.start();
        B.start();
        C.start();
    }
}
